Service (Effect)
特定の機能を凝集したcomponentのこと
実装は隠蔽され、Effect内ではinterfaceを介してアクセスできる
Serviceとは具体的にこれ、というのを示しづらい
Serviceの実体はEffect
どういうものをServiceとして定義するの #?? 副作用を起こすもの、という理解で良い?
code:ts
const program = Effect.gen(function* () {
const maybeRandom = yield* Effect.serviceOption(Random)
const randomNumber = Option.isNone(maybeRandom)
? // the service is not available, return a default value
-1
: // the service is available
yield* maybeRandom.value.next
console.log(randomNumber)
})
defaultで入っている5つのServie
code:ts
type DefaultServices = Clock | ConfigProvider | Console | Random | Tracer
例
code:ts
// program :: Effect<void, never, never>
const program = Effect.gen(function* () {
const now = yield* Clock.currentTimeMillis
yield* Console.log(Application started at ${new Date(now)})
})
Effect.runFork(program)
まじかよ、変やろ、お節介すぎるmrsekut.icon
だって型がおかしいやん
上書きもできる